package study.edumanagesystemspringboot.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zouran
 * createDate：2023/12/26  12:29
 */
public class Counsellor implements Visitor {
    @Override
    public Map<String, Object> visit(Student student) {
        List<Map<String, Object>> maps = student.getAllGrades();
        double sumCredit = 0.0;
        double sumGradePoint = 0.0;
        for (Map<String, Object> map : maps) {
            sumGradePoint += (double) map.get("credit") * (double) map.get("gradePoint");
            sumCredit += (double) map.get("credit");
        }
        Map<String, Object> map = new HashMap<>();
        map.put("identify", student.getIdentify());
        map.put("id", student.getId());
        map.put("name", student.getName());
        map.put("sex", student.getSex());
        map.put("age", student.getAge());
        map.put("department", student.getDepartment());
//        map.put("gradeAverage",student.getGradeAverage());
        map.put("allGrades", student.getAllGrades());
        map.put("phone", student.getPhone());
        map.put("gradeAverage", String.format("%.2f", sumGradePoint / sumCredit));
        return map;
    }

    @Override
    public Map<String, Object> visit(Teacher teacher) {
        Map<String, Object> map = new HashMap<>();
        map.put("identify", teacher.getIdentify());
        map.put("name", teacher.getName());
        map.put("department", teacher.getDepartment());
        map.put("phone", teacher.getPhone());
        return map;
    }
}
